<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-promotion" @click="sendMsg">发送</el-button>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="标题 / 摘要"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="recordId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="100"></el-table-column>
				<el-table-column label="发件组织" prop="fromOrgName" width="150"></el-table-column>
				<el-table-column label="消息标题" prop="subject" width="150"></el-table-column>
				<el-table-column label="内容摘要" prop="subheading" width="350"></el-table-column>
				<el-table-column label="发送时间" prop="createTime" width="170"></el-table-column>
				<el-table-column label="发送人" prop="fromUserName" width="170"></el-table-column>
				<el-table-column label="接收状态" prop="status" width="100">
					<template #default="scope">
						<el-button type="primary" size="small" v-if="scope.row.status==='1'">已接收</el-button>
						<el-button type="danger" size="small" v-else>未接收</el-button>
					</template>
				</el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="210">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="showInfo(scope.row, scope.$index)">查阅</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<send-message v-if="dialog.save" :other-org-list="otherOrgList" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></send-message>
	<inter-details v-if="dialog.detailsSave" ref="interDialog" @closed="dialog.detailsSave=false"></inter-details>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import SendMessage from "@/views/email/sendMessage";
import interDetails from "@/views/email/interDetails";
export default {
	name: 'Email InterWorking',
	components: {
		SendMessage,
		scSelectFilter,
		interDetails
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave:false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "发送组织",
					key: "fromOrgId",
					multiple: false,
					options: [{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "信息状态",
					key: "status",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}, {
						value: '0',
						label: '未接收'
					}, {
						value: '1',
						label: '已接收'
					}],
				}
			],
			otherOrgList:[],
			apiObj: this.$API.email.getMyForwardRecordList,
			search: {
				date:'',
				fromOrgId:'',
				status:'',
				keyword: "",
			}
		}
	},
	mounted() {
		this.getEmailForwardOrgList();
	},
	methods: {
		async getEmailForwardOrgList() {
			var res = await this.$API.email.getEmailForwardOrgList.get();
			if (res.code == 200) {
				if(res.data)
				{
					this.otherOrgList = res.data;
					this.filterData[1].options = this.filterData[1].options.concat(res.data);
				}
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.fromOrgId = data.fromOrgId;
			this.search.status = data.status;
			this.$refs.table.upData(this.search)
		},
		sendMsg(){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		showInfo(row,index)
		{
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.interDialog.open().setData(row);
			})
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
